<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>修改公司信息</title>
		<link type="text/css" rel="stylesheet" href="layui/css/layui.css" />
		<script type="text/javascript" src="layui/layui.js"></script>
		<script type="text/javascript" scc="js/jquery-3.4.1.min.js"></script>
	</head>
	<body>
		<form id="updateCompany" class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					id:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyId" name="companyId" 
						placeholder="请输入id" class="layui-input layui-bg-gray" readonly="readonly" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司名字:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyName" name="companyName" 
						placeholder="请输入公司名字" class="layui-input layui-bg-gray" readonly="readonly" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司logo:
				</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="uploadLogo">
					  <i class="layui-icon">&#xe67c;</i>上传图片
					</button>
						<img id="imgFace" style="width: 120px" src="" /><br />
					<input type="hidden" name="logo" id="logo" value="" class="layui-input">
				</div>
			</div>
			
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司介绍:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyIntr" name="companyIntr" 
						placeholder="请输入公司介绍" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司文化:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyCulture" name="companyCulture" 
						placeholder="请输入公司文化" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					招商热线:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyTel" name="companyTel" 
						placeholder="请输入招商热线" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司地址:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyAddress" name="companyAddress" 
						placeholder="请输入公司地址" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司电话:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyPhone" name="companyPhone" 
						placeholder="请输入公司电话" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司邮箱:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="companyEmail" name="companyEmail" 
						placeholder="请输入公司邮箱" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					url:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="url" name="url" 
						placeholder="请输入公司文化" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					公司图片:
				</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="uploadImg">
					  <i class="layui-icon">&#xe67c;</i>上传图片
					</button>
						<img id="imgFacee" style="width: 120px" src="" /><br />
					<input type="hidden" name="companyImg" id="companyImg" value="" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					经度:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="x" name="x" 
						placeholder="请输入经度" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					纬度:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="y" name="y" 
						placeholder="请输入纬度" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button lay-submit class="layui-btn layui-btn-sm" lay-filter="updateCompany">更新</button>
					<button type="reset" lay-submit class="layui-btn layui-btn-sm">取消</button>
				</div>
			</div>
		</form>
		
		<script>
		//23d66d84-fae1-45d5-bd07-b694662fe579
		layui.use(['form','layer','upload'],function(){
			var form = layui.form,$ = layui.$,layer = layui.layer,upload = layui.upload;
			
			$("#imgFace").attr("src","../"+$("#logo").val());
			
			//执行实例
			  var uploadInst = upload.render({
			    elem: '#uploadLogo' //绑定元素
			    ,url: '../ImageServlet?req=upload' //上传接口
			    ,done: function(res){
			    	 //回显图片
			    	  layer.msg(res.message,{icon:6});
			    	  $("#imgFace").attr("src","../"+res.message);
			    	  //保存名字
			    	  $("#logo").val(res.message);
			    }
			    ,error: function(){
			    }
			  });
			
			  $("#imgFacee").attr("src","../"+$("#companyImg").val());
				
				//执行实例
				  var uploadInst = upload.render({
				    elem: '#uploadImg' //绑定元素
				    ,url: '../ImageServlet?req=upload' //上传接口
				    ,done: function(res){
				    	 //回显图片
				    	  layer.msg(res.message,{icon:6});
				    	  $("#imgFacee").attr("src","../"+res.message);
				    	  //保存名字
				    	  $("#companyImg").val(res.message);
				    }
				    ,error: function(){
				    }
				  });
			
			
			// 表单按钮在监听的时候    updateUser按钮后面的（lay-filter事件名字）
			form.on('submit(updateCompany)',function(res){
				var str = $("#updateCompany").serialize();
				$.post(
					"http://localhost:8080/Dreamcontrol/CompanyAdminServlet?req=companyUpdate",
					str,
					function(res){
					   //success: true，操作成功；false,操作失败 
					   if(res.success == true){
					   	 layer.alert("更新成功");
					   	 //先得到当前iframe层的索引
						var index = parent.layer.getFrameIndex(window.name); 
						//再执行关闭 
						parent.layer.close(index);  
						//关闭父级页面的表格
						parent.layui.table.reload('table');
					   }else{
					   	layer.alert("更新失败");
					   }
					},
					"json"
				);
				return false;
				
			});
			
		})
		</script>
		
		
	</body>
</html>

